package com.jasmine.bjstkserver.server.web;

import com.jasmine.bjstkserver.mapper.WebMapper;
import com.jasmine.bjstkserver.server.web.model.WebEntity;
import com.jasmine.core.constants.BjsConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author : jasmineXz
 */
@Service
public class WebServiceImpl implements WebService {

    @Autowired
    private WebMapper webMapper;

    @Override
    @Cacheable(cacheNames = BjsConstants.Redis.WEB_COLLECT, key = "'userid_' + #userId")
    public Map<String,List<WebEntity>> findList(Integer userId) {
        List<WebEntity> list = webMapper.findList(userId);
        return list.stream().collect(Collectors.groupingBy(WebEntity::getType));
    }

    @Override
    @CacheEvict(cacheNames = BjsConstants.Redis.WEB_COLLECT, key = "'userid_' + #userId")
    public void clearCache(Integer userId) {

    }


}
